package com.cn.kehong.controller;

import com.cn.kehong.api.IDeviceService;
import com.cn.kehong.api.ISysItemService;
import com.cn.kehong.domain.SysDevice;
import com.cn.kehong.domain.SysItem;
import com.cn.kehong.utils.CommonUtil;
import com.cn.kehong.utils.JsonResponse;
import com.cn.kehong.utils.QueryForm;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created On : 2023/12/11.
 * <p>
 * Author : Huiyan
 * <p>
 * Description: 基础数据----设备注册
 */
@Controller
@RequestMapping("/device")
public class DeviceController {

    @Autowired
    private IDeviceService deviceService;




    /**
     * @author : Huiyan feng
     * @date   : 2023/12/11
     * @param  : [queryForm, frontToken]
     * @return : com.cn.jinl.utils.JsonResponse<java.util.List<com.cn.jinl.domain.Device>>
     * @description : getDeviceSelect 根据条件查询设备
     */
    @RequestMapping("/getDeviceSelect/{frontToken}")
    @ResponseBody
    public JsonResponse<List<SysDevice>> getDeviceSelect(@RequestBody QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<SysDevice>> response = new JsonResponse<>();
        List<SysDevice> devices = deviceService.getDeviceSelect(queryForm);
        response.setResult(devices);
        response.setSuccess(true);
        return response;
    }



    /**
     * @author : Huiyan feng
     * @date   : 2023/12/11
     * @param  : [queryForm, frontToken]
     * @return : com.cn.jinl.utils.JsonResponse<java.lang.String>
     * @description : deleteDevice 删除选中的设备数据
     */
    @RequestMapping("/deleteDevice/{frontToken}")
    @ResponseBody
    public JsonResponse<String> deleteDevice(@RequestBody QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = deviceService.deleteDevice(queryForm);
        return CommonUtil.getResponseData(response,result);
    }


    @RequestMapping("/addDevice/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addDevice(@RequestBody List<SysDevice> sysDevices,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = deviceService.addDevice(sysDevices);
        return CommonUtil.getResponseData(response,result);
    }


    //修改
    @RequestMapping("/updateDevice/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateDevice(@RequestBody SysDevice sysDevice, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = deviceService.updateDevice(sysDevice);
        return CommonUtil.getResponseData(response,result);
    }


    //获取所有厂房车间 拼接下拉框
    @RequestMapping("/getAllDeviceSelect/{frontToken}")
    @ResponseBody
    public JsonResponse<List<SysDevice>> getAllDeviceSelect(@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<SysDevice>> response = new JsonResponse<>();
        List<SysDevice> devices = deviceService.getAllDeviceSelect();
        response.setResult(devices);
        response.setSuccess(true);
        return response;
    }

    //通过厂房车间查询线体炉号(线体-炉号)
    @RequestMapping("/getLineByWorkshop/{frontToken}")
    @ResponseBody
    public JsonResponse<List<SysDevice>> getLineByWorkshop(String workshop) throws Exception {
        JsonResponse<List<SysDevice>> response = new JsonResponse<List<SysDevice>>();
        List<SysDevice> lineList = deviceService.getLineByWorkshop(workshop);
        response.setResult(lineList);
        response.setSuccess(true);
        return response;
    }

}
